package com.eastdigit.bpm.listener;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.Expression;

import com.eastdigit.system.model.BusinessException;

public class SetVariableListener implements ExecutionListener {
	
/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Expression name;
	
	private Expression value;

	@Override
	public void notify(DelegateExecution execution) throws Exception {
		 if(name == null){
			 throw new BusinessException("监听变量[name]未指定 !"); 
		 }
		 
		 String variableName = name.getValue(execution).toString();
		 Object variableValue = value == null ? "" : value.getValue(execution);
		 execution.setVariable(variableName, variableValue);
		 

	}

}
